package com.whfc.ms.api.sys.service.impl;

import com.whfc.common.file.FileHandler;
import com.whfc.common.file.FilePathConfig;
import com.whfc.common.result.PageData;
import com.whfc.common.util.RandomUtil;
import com.whfc.entity.dto.OssPathDTO;
import com.whfc.fuum.dto.SysExternalLinkDTO;
import com.whfc.fuum.dto.SysSkinDTO;
import com.whfc.fuum.param.SysSkinAdd;
import com.whfc.fuum.param.SysSkinEdit;
import com.whfc.fuum.service.SysConfigService;
import com.whfc.ms.api.sys.service.MsSysConfigService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author qzexing
 * @version 1.0
 * @date 2020-12-10 19:25
 */
@Service
public class MsSysConfigServiceImpl implements MsSysConfigService {

    @DubboReference(interfaceClass = SysConfigService.class, version = "1.0.0")
    private SysConfigService sysConfigService;

    @Autowired
    private FileHandler fileHandler;

    @Autowired
    private FilePathConfig filePathConfig;

    @Override
    public SysExternalLinkDTO getLinkUrl(Integer deptId, String code, Integer userId) {
        return sysConfigService.getLinkUrl(deptId, code, userId);
    }

    @Override
    public SysSkinDTO getSkin(String host) {
        return sysConfigService.getSkin(host);
    }

    @Override
    public PageData<SysSkinDTO> getSkinList(Integer pageNum, Integer pageSize) {
        return sysConfigService.getSkinList(pageNum, pageSize);
    }

    @Override
    public void addSkin(SysSkinAdd param) {
        sysConfigService.addSkin(param);
    }

    @Override
    public void editSkin(SysSkinEdit param) {
        sysConfigService.editSkin(param);
    }

    @Override
    public void delSkin(Integer skinId) {
        sysConfigService.delSkin(skinId);
    }

    @Override
    public OssPathDTO uploadSkinImg(MultipartFile file) throws Exception {
        String fileName = RandomUtil.getRandomFileName() + ".png";
        String ossKey = filePathConfig.getFilePath("sys/skin", fileName);
        String upload = fileHandler.upload(ossKey, file.getInputStream());
        OssPathDTO data = new OssPathDTO();
        data.setPath(upload);
        return data;
    }

    @Override
    public SysSkinDTO getSkinByDeptId(Integer deptId) {
        return sysConfigService.getSkinByDeptId(deptId);
    }
}
